package dr.joketalker.controller;


import android.app.Activity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import dr.joketalker.R;
import dr.joketalker.Debug.DebugManager;
import dr.joketalker.R.id;
import dr.joketalker.R.layout;

public class DebugController extends Activity implements OnClickListener{
    /** Called when the activity is first created. */
	
	protected TextView m_tvDebug;
	protected Button m_btnClear;

	protected static String m_debug="";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.debug);

        m_tvDebug 		=  (TextView)this.findViewById(R.id.tvDebug);
        m_btnClear 		=  (Button)this.findViewById(R.id.btnClear);
        m_tvDebug.setMovementMethod(new ScrollingMovementMethod());
        

        updateGui();    
        addListeners();
    }
    private void addListeners(){
    	m_btnClear.setOnClickListener(this);
    	
    	
    }
    
    protected void updateGui(){
    	DebugManager myDebug = DebugManager.getInstance();
    	
        if(myDebug.getDebug().length()!=0){
        	m_tvDebug.setText(myDebug.getDebug());
        }else{
        	m_tvDebug.setText("");
        }
    }
    
	@Override
	public void onClick(View v) {
		DebugManager myDebug = DebugManager.getInstance();
		Log.v("me", "click");
		// TODO Auto-generated method stub
		if(v.equals(m_btnClear)){
			Log.v("me", "m_btnClear");
			myDebug.ClearDebug();
			updateGui();
		}
		
	}
	
	public static void appendDebug(String dbg){
		m_debug+=dbg+"\n";
	}
	public static void clearDebug(){
		m_debug="";
	}
	
	
	@Override
	public void onBackPressed() {
	  finish();
	}
}